home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9619 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.3 KB  |  49 lines

  1. Path: watnews.watson.ibm.com!kgold
  2. From: kgold@watson.ibm.com (K Goldman)
  3. Newsgroups: comp.sources.wanted,comp.lang.c,comp.unix.programmer
  4. Subject: Re: Seek unix2dos.c OR help with tr
  5. Date: 11 Mar 1996 15:15:43 GMT
  6. Organization: IBM T.J. Watson Research Center
  7. Distribution: ibm
  8. Message-ID: <4i1g2v$m12@watnews1.watson.ibm.com>
  9. References: <4i0946$7io@nuke.csu.net>
  10. NNTP-Posting-Host: beta.watson.ibm.com
  11.  
  12.  mclean@futon.SFSU.EDU (Emmett Mclean) writes:
  13. |> 
  14. |> Does anyone have the source to a program
  15. |> converting a unix file into dos format?
  16. |> That is, each decimal 10 char is replaced
  17. |> with a series of a 10 and 13.
  18. |> 
  19. |>[snip]
  20. |> 
  21. |> I will be using it to download zipped binaries
  22. |> files from a unix box.
  23. |> 
  24. |> Ah, writing the program is a bit trickier
  25. |> than the little program below since the
  26. |> program exits prematurely because getchar reads
  27. |> EOF from its input - before getting to
  28. |> the real EOF.
  29. |> 
  30. |> #include <stdio.h>
  31. |> main(){
  32. |> char c;
  33. |> while(EOF!=(c=getchar())){
  34. |>  if(10==c)putchar(13);
  35. |>  putchar(c);
  36. |>  }
  37. |>  putchar(10);
  38. |> }
  39. |> 
  40.  
  41. The tricky part is that getchar() returns an int, not a char.
  42. It does that so EOF does not collide with a legal 8 bit char.
  43.  
  44. BTW, if you're using an AIX machine, aix2dos and dos2aix are
  45. included and do exactly what you want.
  46.  
  47. -- 
  48. Ken Goldman   kgold@watson.ibm.com   914-784-7396
  49.